package com.hdl.servlet.mallproduct;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hdl.entity.MallComment;
import com.hdl.entity.MallProduct;
import com.hdl.service.MallCommentService;
import com.hdl.service.MallProductService;
import com.hdl.service.impl.MallCommentServiceImpl;
import com.hdl.service.impl.MallProductServiceImpl;

@WebServlet("/mallproductshow.let")
public class MallProductShowServlet extends HttpServlet{
    
	private  MallProductService mp = new MallProductServiceImpl();
	
	private MallCommentService service = new MallCommentServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	       String id = request.getParameter("id");
	              
	       MallProduct shop = mp.SelectProductById(id);
	       
	       //查询该商品的评论
	       List<MallComment> list = service.findCommentById(id);
	       
	       //将数据存入请求域中
	       request.setAttribute("commentList", list);
	       request.setAttribute("shop", shop);
	       
	       request.getRequestDispatcher("/shopdetail.jsp").forward(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	   doGet(req, resp);
	}
	
}
